package com.base.look.presenter;

import android.app.Activity;

import com.base.commonlib.base.presenter.BasePresenter;
import com.base.commonlib.http.RealNetWorkUtil;
import com.base.commonlib.http.utils.CallBackImpl;
import com.base.commonlib.sp.SpUtil;
import com.base.look.bean.LookListBean;
import com.base.look.view.LookExamineView;
import com.base.look.view.LookView;

import java.util.HashMap;
import java.util.Map;

import io.reactivex.disposables.Disposable;

public class LookExaminePresenter extends BasePresenter<LookExamineView> {
    public LookExaminePresenter(LookExamineView view, Activity activity) {
        super(view, activity);
    }


    /**
     *
     * @param commentId  评论的时候  commentId 为空    回复的时候为回复信息的id
     * @param content 内容
     * @param postId  当前数据的id
     */
    public void addComment(final int type, String commentId, String content, String postId, final int position){
        Map<String, String> map = new HashMap<>();
        map.put("commentId",commentId);
        map.put("content",content);
        map.put("postId",postId);
        Disposable enqueue = RealNetWorkUtil.postContent().method("api-view/comment")
                .content(map)
                .build().enqueue(String.class, new CallBackImpl<String>() {
                    @Override
                    public void onError(int code, String msg, String errMsg) {
                        mView.showError();
                        mView.returnCommentReplyError(msg);
                    }

                    @Override
                    public void onNext(String s) {
                        mView.returnCommentReplySuccess(s,type,position);
                    }
                });
        mCompositeDisposable.add(enqueue);
    }


    /**
     * 看看审核通过/不通过
     * @param id id
     * @param position 位置
     */
    public void adopt(String id, final int position,Integer status){
        Map<String, Object> map = new HashMap<>();
        map.put("id",id);
        map.put("verify",status);
        Disposable enqueue = RealNetWorkUtil.get().method("api-view/verifyPost").params(map)
                .build().enqueue(String.class, new CallBackImpl<String>() {
                    @Override
                    public void onError(int code, String msg, String errMsg) {
                        mView.showError();
                       // mView.returnThumbsError(msg);
                    }

                    @Override
                    public void onNext(String msg) {
                        mView.returnAdoptSuccess("请求成功",position);
                    }
                });
        mCompositeDisposable.add(enqueue);
    }
    /**
     * 删除看看
     * @param id id
     * @param position 位置
     */
    public void delete(String id, final int position){
        Map<String, Object> map = new HashMap<>();
        map.put("id",id);
        Disposable enqueue = RealNetWorkUtil.get().method("api-view/delete").params(map)
                .build().enqueue(String.class, new CallBackImpl<String>() {
                    @Override
                    public void onError(int code, String msg, String errMsg) {
                        mView.showError();
                        mView.returnDeleteError(msg);
                    }

                    @Override
                    public void onNext(String msg) {
                        mView.returnDeleteSuccess(msg,position);
                    }
                });
        mCompositeDisposable.add(enqueue);
    }


    /**
     * 获取列表数据
     * @param page  页数
     * @param limit  每页显示多少数据
     */
    public void lookList(final Integer page, Integer limit){
        if (page == 1){
            mView.showPb();
        }
        Map<String, Integer> map = new HashMap<>();
        map.put("page",page);
        map.put("limit", limit);
        Disposable enqueue = RealNetWorkUtil.postContent().method("api-view/listUnVerify")
                .content(map)
                .build().enqueue(LookListBean.class, new CallBackImpl<LookListBean>() {
                    @Override
                    public void onError(int code, String msg, String errMsg) {
                        if (page == 1){
                            mView.hidePb();
                        }
                        mView.showError();
                        mView.returnListError();
                    }

                    @Override
                    public void onNext(LookListBean list) {
                        if (page == 1){
                            mView.hidePb();
                        }
                        if (page==1){
                            //刷新
                            if (list!=null &&list.getRows() != null&&list.getRows().size()>0){
                                mView.returnLoolListSuccess(list);
                            }else {
                                mView.returnNoData();
                            }
                        }else {
                            //更多
                            if (list!=null &&list.getRows() != null&&list.getRows().size()>0){
                                mView.returnMoreList(list);
                            }else {
                                mView.returnNoMoreData();
                            }
                        }
                    }
                });

        mCompositeDisposable.add(enqueue);
    }

}
